package	com.mes.web.controller.warning;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mes.entity.warning.Warning;
import com.mes.service.warning.WarningService;
import com.mes.utils.ResponseUtil;
/**
 *
 *@ClassName: WarningController
 *@Description: 报警信息
 *@Author tdd
 *@Date 2019-06-06 09:37:43
 *@version 1.0
*/
@Controller
@RequestMapping("/warning")
public class WarningController{
	@Resource WarningService warningService;
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	@RequestMapping("/queryById")
	@ResponseBody
	public Warning queryById(Long id) {
		Warning param = warningService.queryById(id);
		return param;
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<Warning> queryAllByMution(Warning param) {
		List<Warning> list = warningService.queryAllByMution(param);
		return list;
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/list")
	public void list(Warning param,HttpServletResponse response) throws Exception{
		/*
		 * 条件分页查询内容
		 */
		List<Warning> list = warningService.findPageByMution(param);
		/*
		 * 条件查询总条数
		 */
		Integer total = warningService.selectCountByMution(param);
		/*
		 * 转为json数据传至页面
		 */
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("total", total);
		jsonObject.put("rows", list);
		ResponseUtil.write(response, jsonObject);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/insert")
	public void insert(Warning param, HttpServletResponse response) throws Exception{
		Long id = warningService.insert(param);
		ResponseUtil.write(response, id);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/update")
	public void update(Warning param,HttpServletResponse response) throws Exception{
		Integer count = warningService.update(param);
		ResponseUtil.write(response, count);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = warningService.delete(ids);
		ResponseUtil.write(response, count);
	}
	/** 
	 * 根据主键拼接的字符串修改状态返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	 */
	@RequestMapping("/updateWstareByIds")
	public void updateWstareByIds(String ids,String wstare,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = warningService.updateWstareByIds(ids,wstare);
		ResponseUtil.write(response, count);
	}
}
